public class Predator extends Fish {
    public static final int AGE_TO_DIE = 20;
    private final int MAX_STEP = 2;
    private static final int EATEN_TO_SPAWN = 2;

    private int fishesEaten;

    public Predator(Position position) {
        super(position);
        fishesEaten = 0;
    }

    @Override
    public String toString() {
        return String.format("This is predator, its position is %s", position);
    }

    @Override
    public Predator clone() {
        try {
            Predator obj = (Predator) super.clone();
            obj.position = position;
            obj.age = age;
            return obj;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError(e);
        }
    }

    @Override
    public void eat() {
        fishesEaten++;
    }

    @Override
    public boolean isTimeToSpawn() {
        if(fishesEaten == EATEN_TO_SPAWN){
            System.out.println(this);
        }

        return fishesEaten == EATEN_TO_SPAWN;
    }

    @Override
    public boolean canEat(boolean victimOnPosition) {
        return victimOnPosition;
    }

    @Override
    public Fish spawn() {
        fishesEaten = 0;
        return new Predator(position);
    }

    @Override
    public void die() {
        if (age == AGE_TO_DIE) {
            isDead = true;
        }
    }

    @Override
    public boolean isDead() {
        return isDead;
    }

    @Override
    public int getMaxStep() {
        return MAX_STEP;
    }


    @Override
    public void move(MotionInformation motionInformation) {
        if(motionInformation.getDirection()==Direction.FAKE){
            position.changePosition(Randomize.selectDirection(),MAX_STEP);
        }else {
            position.changePosition(motionInformation);
        }
    }


    @Override
    public CreaturesType getType() {
        return CreaturesType.Predator;
    }


}

